<?php require_once('Connections/STN.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_RSpostagens = 1;
$pageNum_RSpostagens = 0;
if (isset($_GET['pageNum_RSpostagens'])) {
  $pageNum_RSpostagens = $_GET['pageNum_RSpostagens'];
}
$startRow_RSpostagens = $pageNum_RSpostagens * $maxRows_RSpostagens;


$maxRows_RSpostagens = 10;
$pageNum_RSpostagens = 0;
if (isset($_GET['pageNum_RSpostagens'])) {
  $pageNum_RSpostagens = $_GET['pageNum_RSpostagens'];
}
$startRow_RSpostagens = $pageNum_RSpostagens * $maxRows_RSpostagens;

mysql_select_db($database_STN, $STN);

///query

	//categoria
	if(isset($_GET['categoria'])){
	$categoria=$_GET['categoria'];
	
	$query_RSpostagens = "select pos.* from tb_postagens pos
	JOIN tb_periodos per ON(pos.POS_PER_CODIGO=per.PER_CODIGO)
	JOIN tb_categorias cat ON(per.PER_CAT_CODIGO=cat.CAT_CODIGO)
	where (pos.POS_PUBLICA='2') and (cat.CAT_CODIGO='$categoria') order by pos.POS_CODIGO desc";
	}
	
	//filtro
	if(isset($_GET['filtro'])){
	$filtro=@$_GET['filtro'];
	
	$query_RSpostagens = "select pos.* from tb_postagens pos
	JOIN tb_periodos per ON(pos.POS_PER_CODIGO=per.PER_CODIGO)
	JOIN tb_categorias cat ON(per.PER_CAT_CODIGO=cat.CAT_CODIGO)
	where (pos.POS_PUBLICA='2') and (pos.POS_TITULO like '%$filtro%' or pos.POS_PALAVRAS_CHAVES like '%$filtro%') order by pos.POS_CODIGO desc";
	}
	
	//periodo
	if(isset($_GET['periodo'])){
	$periodo=@$_GET['periodo'];
	
	$query_RSpostagens = "select pos.* from tb_postagens pos
	JOIN tb_periodos per ON(pos.POS_PER_CODIGO=per.PER_CODIGO)
	JOIN tb_categorias cat ON(per.PER_CAT_CODIGO=cat.CAT_CODIGO)
	where (pos.POS_PUBLICA='2') and (per.PER_CODIGO='$periodo') order by pos.POS_CODIGO desc";
	}



$query_limit_RSpostagens = sprintf("%s LIMIT %d, %d", $query_RSpostagens, $startRow_RSpostagens, $maxRows_RSpostagens);
$RSpostagens = mysql_query($query_limit_RSpostagens, $STN) or die(mysql_error());
$row_RSpostagens = mysql_fetch_assoc($RSpostagens);

if (isset($_GET['totalRows_RSpostagens'])) {
  $totalRows_RSpostagens = $_GET['totalRows_RSpostagens'];
} else {
  $all_RSpostagens = mysql_query($query_RSpostagens);
  $totalRows_RSpostagens = mysql_num_rows($all_RSpostagens);
}
$totalPages_RSpostagens = ceil($totalRows_RSpostagens/$maxRows_RSpostagens)-1;

$queryString_RSpostagens = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_RSpostagens") == false && 
        stristr($param, "totalRows_RSpostagens") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_RSpostagens = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_RSpostagens = sprintf("&totalRows_RSpostagens=%d%s", $totalRows_RSpostagens, $queryString_RSpostagens);

mysql_select_db($database_STN, $STN);
$query_RSvideo = "SELECT VID_CODIGO, VID_URL FROM tb_videos LIMIT 6;";
$RSvideo = mysql_query($query_RSvideo, $STN) or die(mysql_error());
$row_RSvideo = mysql_fetch_assoc($RSvideo);
$totalRows_RSvideo = mysql_num_rows($RSvideo);


//limitar texto
	function limitarTexto($texto){
		$texto = substr($texto, 0, strrpos(substr($texto, 0, 200), ' '));
   		return $texto;
	}

//conversor de data
	function bancobr($databanco){
		$ano = substr($databanco, 0, 4);
		$mes = substr($databanco, 5, 2);
		$dia = substr($databanco, 8, 2);
		$databr = $dia . "/" . $mes . "/" . $ano;
		return $databr;
	}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A Sala do Tio Naldinho</title>


<link rel="stylesheet" href="css/style.css" type="text/css" >

<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript" src="js/banner.js"></script>

<script type="text/javascript" src="banner/jsbanner.js"></script>

<script type="text/javascript" src="js/jquery.cycle.all.js"></script>

<link rel="stylesheet" href="banner/stylebanner.css">

<!--janela modal-->
<script type="text/javascript">


$(document).ready(function() {	

	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(2000); 
	
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

</script>

<!--fim da janela de contato-->

<script type="text/javascript" src="js/jcarousellite.js"></script>

<script type="text/javascript">

$(function(){

   $(".carosel").jCarouselLite({

     btnNext: ".next",

     btnPrev: ".prev",

     visible: 3,

     auto: 0,

     speed: 1000

   })

})
</script>

<script type="text/javascript" src="colorbox/jquery.colorbox.js"></script>

<link rel="stylesheet" href="colorbox.css" type="text/css" />

<script>
		$(document).ready(function(){
			//Examples of how to assign the ColorBox event to elements
			$(".group1").colorbox({rel:'group1'});
			$(".group2").colorbox({rel:'group2', transition:"fade"});
			$(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
			$(".group4").colorbox({rel:'group4', slideshow:true});
			$(".ajax").colorbox();
			$(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
			$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
			$(".inline").colorbox({inline:true, width:"50%"});
			$(".callbacks").colorbox({
				onOpen:function(){ alert('onOpen: colorbox is about to open'); },
				onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
				onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
				onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
				onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
			});
			
			//Example of preserving a JavaScript event for inline calls.
			$("#click").click(function(){ 
				$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
				return false;
			});
		});
	</script>

</head>

<body>

<!--inicio do quadro verde da logo-->
<div style="width:100%; height:250px;background:#1A2D1C;margin-left:0px;">


<div class="logo" style=" text-align:center;">



<!--div da logo-->
<img src="imagens/logo2.png" style=" margin-top: 60px;"/>

</div><!--fim da div da logo-->

</div><!--fimm do fundo verde da logo-->

<div style="width:99%; height:10px;background:#12B225;margin-left:-2px;top:250px;box-shadow:0 0 .5em #000;position:absolute;z-index:1010;">
</div><!--fim da linha com efeito da logo-->


<!--div central de todo o conteudo-->
<div class="all">

<!--inicio do menu-->
<div class="menu">
<ul class="menuul">
	<li><span><a href="index.php">IN&Iacute;CIO</a></span></li>
    <li><span><a href="sobre.php">TIO NALDINHO</a></span></li>
    <li><span><a href="#">A SALA</a></span>
    	<ul class="submenu">
        	<li><span><a href="videos.php">VIDEOS</a></span></li><br />
            <li><span><a href="documentos.php">DOCUMENTOS</a></span></li>
            <li><span><a href="albuns.php">FOTOS ANTIGAS</a></span></li>
        </ul>
    
    </li>
    <li><span><a href="#dialog2" name="modal">CONTATO</a></span></li>
</ul>

</div><!--fim do menu-->

<!--div da do formulario de busca-->
<div class="busca">
<form action="?" method="get">
<table>
<tr>
	<td>
<input type="text" name="filtro" placeholder="buscar"></td><td><button><img src="imagens/lupa.png" /></button></td>
</tr>
</table>
</form>
</div><!--fim do formulario de busca-->

<!--inicio da tabela do body-->
<table>
<tr>
	<td width="196" valign="top" >
	<div class="menuesquerdo">
    <ul>
    	<li><span class="titulomenu"><a href="postagens.php?categoria=1">HISTORIA GERAL</a></span></li>
        <div class="bg"></div>
        <li><span><a href="?periodo=1">Pr&eacute;-Historia</a></span></li>
        <li><span><a href="?periodo=2">Idade-Antiga</a></span></li>
        <li><span><a href="?periodo=3">Idade-M&eacute;dia</a></span></li>
        <li><span><a href="?periodo=4">Idade-Moderna</a></span></li>
        <li><span><a href="?periodo=5">Idade-Contepor&acirc;nea</a></span></li>
     </ul>
	</div>
    
    <div class="menuesquerdo2">
    <ul>
    	<li><span class="titulomenu"><a href="postagens.php?categoria=2">HISTORIA DO BRASIL</a></span></li>
        <div class="bg"></div>
        <li><span><a href="?periodo=6">Pr&eacute;-Col&ocirc;nial</a></span></li>
        <li><span><a href="?periodo=7">Col&ocirc;nial</a></span></li>
        <li><span><a href="?periodo=8">Imp&eacute;rial</a></span></li>
        <li><span><a href="?periodo=9">Rep&uacute;blica</a></span></li>
     </ul>
	</div>
    
    <div class="menuesquerdo3">
    <ul>
    	<li><span class="titulomenu"><a href="postagens.php?categoria=3">RIO GRANDE DO NORTE</a></span></li>
        <div class="bg"></div>
        <li><span><a href="?periodo=10">Pr&eacute;-Col&ocirc;nia</a></span></li>
        <li><span><a href="?periodo=11">Col&ocirc;nia</a></span></li>
        <li><span><a href="?periodo=12">Imp&eacute;rio</a></span></li>
        <li><span><a href="?periodo=13">Rep&uacute;blica</a></span></li>
     </ul>
	</div>
    </td><!--fim do menu lateral esquerdo-->
<!--conteudo-->
	<td width="700" valign="top"><!--conteudo-->
<div class="post" style=" margin-top:30px ;">
        
        <?php do { ?>
		<div class="post">          
         <div class="post-data"><?php echo bancobr($row_RSpostagens['POS_DATA']); ?></div>
		 <div class="post-titulo"><a href="postagens2.php?id=<?php echo $row_RSpostagens['POS_CODIGO'] ?>"><?php echo $row_RSpostagens['POS_TITULO']; ?></a></div>
         <div class="post-texto"><?php echo limitarTexto($row_RSpostagens['POS_TEXTO']); ?><a class="leiamais" href="postagens2.php?id=<?php echo $row_RSpostagens['POS_CODIGO'] ?>"> leia mais...</a></div>
           	
         
         </div>
         <hr />
          <?php } while ($row_RSpostagens = mysql_fetch_assoc($RSpostagens)); ?>


      <table border="0">
  <tr>
    <td><?php if ($pageNum_RSpostagens > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_RSpostagens=%d%s", $currentPage, 0, $queryString_RSpostagens); ?>">Primeiro</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_RSpostagens > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_RSpostagens=%d%s", $currentPage, max(0, $pageNum_RSpostagens - 1), $queryString_RSpostagens); ?>">Anterior</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_RSpostagens < $totalPages_RSpostagens) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_RSpostagens=%d%s", $currentPage, min($totalPages_RSpostagens, $pageNum_RSpostagens + 1), $queryString_RSpostagens); ?>">Pr&oacute;ximo</a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_RSpostagens < $totalPages_RSpostagens) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_RSpostagens=%d%s", $currentPage, $totalPages_RSpostagens, $queryString_RSpostagens); ?>">&Uacute;ltimo</a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
      
	</div>
</td>
    </tr><!--fim do conteudo-->	
    
	<tr valign="top"><!--carosel-->
	<td colspan="2">

<div id="carosel" style="margin:100px 0 0;margin-left:100px;">
<button class="prev"></button>
<button class="next"></button>
 <div class="carosel">

 <ul>
 <?php do { ?>
     <li><?php echo $row_RSvideo['VID_URL'] ?> </li>
     <?php } while ($row_RSvideo = mysql_fetch_assoc($RSvideo)); ?>
 </ul>

 </div><!--fim carosel id--> 
</div><!-- fim carosel class-->
</td>
</tr>

</table><!--fim da tabela central-->

</div><!--Fim da div central(all)-->

<div class="borderfooter">
</div>
<div class="rodape">
<!--copyrignt-->
<div class="copy">
	&copy;copyright <?php echo $programadores ?><br />
    Todos os direitos reservado.
</div>
</div>

<!--div da pagina de contato-->
<div id="boxes">
<div id="dialog2" class="window">
 <form action="?" method="post">
     <input type="text" name="nome" placeholder="Nome" size="50px" style="padding:10px;" /><br /><br />
     <input type="email" name="email" placeholder="Email" size="50px" style="padding:10px;" /><br /><br />
     <textarea style="width:350px;height:200px;"></textarea><br />
     <input type="submit" value="Enviar" onclick="window.alert('Email enviado.\n\n Obrigado.');" />
     <input type="button" value="Fechar" class="close"/>
</form>
</div>
</div>
<!-- Fim Janela Modal da pagina de contato -->
<!-- Máscara para cobrir a tela -->
  <div id="mask"></div>

</div>
<!--fim da div da mascara-->

</body>
</html>
<?php
mysql_free_result($RSpostagens);
?>
